<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期倒计时工具</title>
    <link rel="stylesheet" href="../css/all.min.css">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #ffffff;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }
        #countdown-input {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
            width: 80%;
            max-width: 600px;
            background-color: #f9f9f9;
            padding: 30px;
            border-radius: 20px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            transition: box-shadow 0.3s ease;
        }
        #countdown-input:hover {
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        }
        #target-date {
            padding: 15px 20px;
            font-size: 18px;
            border: 1px solid #e0e0e0;
            border-radius: 10px;
            margin-right: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
            appearance: none;
            -webkit-appearance: none;
            -moz-appearance: none;
            background-color: #ffffff;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="%23666"><polygon points="0,0 12,0 6,12"/></svg>');
            background-repeat: no-repeat;
            background-position: right 20px center;
            background-size: 15px;
            width: 200px;
        }
        #target-date:focus {
            border-color: #28a745;
            box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.2);
            outline: none;
        }
        #countdown-input button {
            padding: 15px 30px;
            font-size: 18px;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            margin-right: 20px;
            transition: background-color 0.3s ease, transform 0.3s ease;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        }
        #start-btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        #start-btn:hover {
            transform: scale(1.05);
        }
        #reset-btn {
            background-color: #808080;
            color: white;
        }
        #reset-btn:hover {
            transform: scale(1.05);
        }
        #countdown-display {
            font-size: 80px;
            font-weight: bold;
            color: #333;
            text-align: center;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
            background-color: #f9f9f9;
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 80%;
            transition: box-shadow 0.3s ease;
        }
        #countdown-display:hover {
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 40px;
            border: 1px solid #888;
            width: 350px;
            text-align: center;
            border-radius: 20px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 40px;
            font-weight: bold;
            transition: color 0.3s ease;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="countdown-input">
        <input type="date" id="target-date" placeholder="选择目标日期">
        <button id="start-btn" onclick="startCountdown()">开始倒计时</button>
        <button id="reset-btn" onclick="resetCountdown()">重置</button>
    </div>
    <div id="countdown-display"></div>
    <div id="myModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <p>请选择有效的目标日期！</p>
        </div>
    </div>
    <script>
        let countdownInterval;
        function startCountdown() {
            const targetDateInput = document.getElementById('target-date');
            const targetDate = new Date(targetDateInput.value);
            const now = new Date();
            if (isNaN(targetDate.getTime())) {
                const modal = document.getElementById('myModal');
                modal.style.display = 'block';
                const span = document.getElementsByClassName("close")[0];
                span.onclick = function () {
                    modal.style.display = 'none';
                };
                window.onclick = function (event) {
                    if (event.target === modal) {
                        modal.style.display = 'none';
                    }
                };
                return;
            }
            if (countdownInterval) {
                clearInterval(countdownInterval);
            }
            countdownInterval = setInterval(() => {
                const distance = targetDate - now;
                if (distance < 0) {
                    clearInterval(countdownInterval);
                    document.getElementById('countdown-display').innerHTML = '倒计时已结束！';
                    return;
                }
                const days = Math.floor(distance / (1000 * 60 * 60 * 24));
                const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                const seconds = Math.floor((distance % (1000 * 60)) / 1000);
                document.getElementById('countdown-display').innerHTML = `${days} 天 ${hours} 小时 ${minutes} 分钟 ${seconds} 秒`;
                now.setSeconds(now.getSeconds() + 1);
            }, 1000);
        }
        function resetCountdown() {
            if (countdownInterval) {
                clearInterval(countdownInterval);
            }
            document.getElementById('target-date').value = '';
            document.getElementById('countdown-display').innerHTML = '';
        }
    </script>
</body>
</html>
    